package cn.xiuxius.askbox.controller.user;


import cn.xiuxius.askbox.common.constant.DataState;
import cn.xiuxius.askbox.pojo.dto.add.AnswerAddDTO;
import cn.xiuxius.askbox.pojo.dto.query.AnswerQueryDTO;
import cn.xiuxius.askbox.pojo.result.Result;
import cn.xiuxius.askbox.pojo.vo.AnswerVO;
import cn.xiuxius.askbox.service.IAnswerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaoxiu
 * @since 2024-07-20
 */
@Api(tags = "用户-回复接口")
@RestController("userAnswerController")
@RequestMapping("/user/answers")
public class AnswerController {
    @Autowired
    private IAnswerService answerService;

    @ApiOperation("根据提问uuid回复问题")
    @PostMapping
    public Result submitAnswer(@Validated @RequestBody AnswerAddDTO dto) {
        answerService.submitAnswer(dto);
        return Result.success();
    }

    @ApiOperation("根据提问uuid查询回答")
    @GetMapping("/askUuid/{uuid}")
    public Result getAnswerByAskUuid(@PathVariable String uuid) {
        AnswerQueryDTO dto = new AnswerQueryDTO();
        dto.setState(DataState.ALIVE);
        dto.setAskUuid(uuid);

        AnswerVO vo = answerService.getAnswerByAskUuid(dto);
        //数据脱敏
        vo.setIp(null);
        vo.setAgent(null);
        vo.setUpdateTime(null);
        vo.setState(null);
        return Result.success(vo);
    }

}
